package com.axx.android.profile.message.activity;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.widget.Button;
import android.widget.LinearLayout;

import com.axx.android.R;
import com.axx.android.base.BaseActivity;
import com.axx.android.base.BaseFragment;
import com.axx.android.home.adapter.ViewPagerAdapter;
import com.axx.android.profile.message.fragment.MessageListFragment;
import com.axx.android.profile.message.model.ChangeEvent;
import com.sevenheaven.segmentcontrol.SegmentControl;

import org.greenrobot.eventbus.EventBus;

import java.util.Arrays;

import butterknife.Bind;
import butterknife.ButterKnife;

public class MessageActivity extends BaseActivity {

    @Bind(R.id.btn_back)
    Button btnBack;
    @Bind(R.id.tablayout)
    TabLayout tablayout;
    @Bind(R.id.viewpager)
    ViewPager viewpager;
    @Bind(R.id.activity_message)
    LinearLayout activityMessage;
    @Bind(R.id.segment_control)
    SegmentControl mSegmentControl;

    private String direction = "1";


    @Override
    public int getLayoutId() {
        return R.layout.activity_message;
    }

    @Override
    public void init(Bundle savedInstanceState) {
        BaseFragment baseFragment = MessageListFragment.newInstance(direction, "0");
        baseFragment.setTitle("正在路上");

        BaseFragment baseFragment2 = MessageListFragment.newInstance(direction, "1");
        baseFragment2.setTitle("已到达");


        viewpager.setAdapter(new ViewPagerAdapter(getSupportFragmentManager(), Arrays.asList(
                baseFragment,
                baseFragment2
        )));
        tablayout.setupWithViewPager(viewpager);
        mSegmentControl.setOnSegmentControlClickListener(new SegmentControl.OnSegmentControlClickListener() {
            @Override
            public void onSegmentControlClick(int index) {
                switch (index) {
                    case 0:
                        EventBus.getDefault().post(new ChangeEvent("1"));
                        break;
                    case 1:
                        EventBus.getDefault().post(new ChangeEvent("2"));
                        break;
                }
            }
        });
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
